﻿using PracticeCentre.Modeles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using PracticeCentre.DataControl;
using PracticeCentre.Common;

namespace PracticeCentre.Business
{
    public class InterPage
    {
        public static PageModel<InterModel> List(PageModel<InterModel> page)
        {
            try
            {
                SqlParameter[] sqlpar = new SqlParameter[]
                {
                        new SqlParameter("@sys_PageIndex",page.PageNumber),//设置当前页码
                    new SqlParameter("@sys_PageSize",page.PageSize),//设置每页显示的数据
                    new SqlParameter("@sys_Table","Student"),//设置表名
                    new SqlParameter("@sys_Key","id"),//设置主键
                    new SqlParameter("@sys_Where"," "),//设置条件
                    new SqlParameter("@sys_Order","id"),//设置按什么列排序
                    new SqlParameter("@sys_AscOrDesc",""),//设置升降序，默认降序
                    new SqlParameter("@pageCount",page.PageCount),//设置总页数
                    new SqlParameter("@recordCount",page.RowCount)//设置总行数
                };
                sqlpar[7].Direction = ParameterDirection.Output;
                sqlpar[8].Direction = ParameterDirection.Output;
                int pagecount = 0;
                int rowcount = 0;
                DataControlHelper con = new DataControlHelper();
                DataTable table = con.ExecuteDataTable<InterModel>(ProceduresConfig.GeneralPaging, out pagecount, out rowcount,sqlpar);
                DataModelHandler<InterModel> hander = new DataModelHandler<InterModel>();
                List<InterModel> model = hander.FillModel(table);
                page.PageCount = pagecount;
                page.RowCount = rowcount;
                page.DataList = model;
                return page;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
